package org.restlesscode.javersion;

import java.util.HashMap;
import java.util.Map;

/**
 * An SvnObject represents an object that is in a state ready to
 * be read or written from an SVN repository. It defines a byte array
 * content field that represents the content of the file in SVN. It also
 * defines the set of SVN properties associated with the written file.
 * These properties can be strings or binary. Finally, the version and
 * transcoder name are specified so that they can be written into the
 * metadata of the file. 
 */
public class SvnObject {

	protected byte[] content = null;
    protected Map<String, SvnPropertyObject> properties;
    protected String version;
    protected String transcoderName;

    protected SvnObject() { }

    /**
     * Create an SvnObject from the given content, properties, version, and
     * transcoder. This object will be in a state ready to be saved to SVN.
     * @param content Body of the SVN file
     * @param properties SVN properties of the file
     * @param version Version of the serialization, convenience field
     * @param transcoderName Transcoder used to serialize object, convenience field
     */
	public SvnObject(byte[] content, Map<String, SvnPropertyObject> properties,
                     String version, String transcoderName) {
        this.content = content;
        this.properties = properties;
        this.version = version;
        this.transcoderName = transcoderName;
    }

    /**
     * Create an empty SvnObject with no properties and no body.
     * @param version Version of the serialization, convenience field
     * @param transcoderName Transcoder used to serialize the object, convenience field
     */
    public SvnObject(String version, String transcoderName) {
        this.version = version;
        this.transcoderName = transcoderName;
        this.properties = new HashMap<String, SvnPropertyObject>();
    }

    /**
     * Return the content of the obejct as a byte array.
     * @return
     */
    public byte[] getContent() {
        return this.content;
    }

    /**
     * Set the content to a byte array.
     * @param content
     */
    public void setContent(byte[] content) {
        this.content = content;
    }

    /**
     * Set an SVN property field.
     * @param propertyName Property to set
     * @param value value of property
     */
    public void setProperty(String propertyName, SvnPropertyObject value) {
        this.properties.put(propertyName, value);
    }

    /**
     * Return an SVN property.
     * @param propertyName property field to return
     * @return
     */
    public SvnPropertyObject getProperty(String propertyName) {
        return this.properties.get(propertyName);
    }

    /**
     * Return map of SVN properties.
     * @return
     */
    public Map<String, SvnPropertyObject> getProperties() {
        return this.properties;
    }

    /**
     * Return version of the object.
     * @return
     */
    public String getVersion() {
        return this.version;
    }

    /**
     * Return the name of the transcoder used to serialize object.
     * @return
     */
    public String getTranscoderName() {
        return this.transcoderName;
    }
}
